const router = require('../router/comment.js')
const db = require('../db/index')
exports.getComment = (req, res) => {
	const sql = `select * from ev_comments where art_id = ?`

	db.query(sql, req.params.art_id, (err,results)=>{
		if(err)
			return res.cc(err)
		if(results.length <= 0)
			return res.cc('获取评论失败!!')
		res.send({
			status:0,
			message:'获取文章评论信息成功！',
			data:results
		})
	})
}

exports.addComment = (req, res) => {

		const sql = `insert into ev_comments set ?`
		const commentInfo={
			...req.body,
			 user_id: req.user.id,
			 date:new Date().Format("yyyy/MM/dd HH:mm"),
		}
		db.query(sql, commentInfo, (err, results) => {
		  if (err) return res.cc(err)
		  if (results.affectedRows !== 1) 
			return res.cc('发布评论失败！')
		  res.cc('发布文章成功', 0)
		})
	}
